<?php
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include '../operations/connection.php';	
include_once 'substring-comment.php';


$rows_per_page = 5;

$page_start = ( $page - 1 ) * $rows_per_page;
$page_end = $page * $rows_per_page; 

$queryListErrorByIDPr = mysql_query("SELECT pr.IDManager , tp.IDTest, tp.IDProject, tp.IDEmployee, tp.Title, tp.TextTest, tp.Time, tp.`Status`,e.FullName,tp.`Delete`,
			   (select c.Comment from pr_comment c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = tp.IDTest order by c.DateComment DESC limit 1) as Comment_C,
			   (select e.FullName from pr_comment c, employee e 
									 where c.IDEmployee = e.IDEmployee and c.IDTestProject = tp.IDTest order by c.DateComment DESC limit 1) as FullName_C
									 
			   FROM pr_testproject tp, employee e,pr_project pr WHERE pr.IDProject = tp.IDProject AND tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			   AND tp.`Delete` = 1 ORDER BY IDTest DESC LIMIT $page_start,$rows_per_page ");

?>
		<div class="divError divinvi" >
			<div class="rf-p divListError">
				<ul>
					<li><a  class="linkAction" href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1">
						<img src="images/list.png" alt="" />
						<span
							style="display: inline-block; width: 100%"><?php echo $l_error?>
						</span> </a></li>
					<li style="left: 150px"><a  class="linkAction" href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=2"><img
							src="images/recyclebin_empty.png" alt="" /><span
							style="display: inline-block; width: 100%"><?php echo $l_reclycle?>
						</span> </a></li>
					<li style="left: 150px"><a  class="linkAction" href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=1"><img
							src="images/reload.png" alt="" /><span
							style="display: inline-block; width: 100%"><?php echo $l_refresh?>
						</span> </a></li>
					<?php if($_SESSION['posmanager']==1){?>
					<li style="float: right;width: auto;text-align: right;padding: 20px 20px">
						<a href="#" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ processEmptyError(<?=$id?>,<?=$id_employee?>,1,this);return true;}else{return false;}">[ Empty Error]</a></li>
					<?php }?>
				</ul>
			</div>
			
			<div id='ajaxdelete'>
			<table width="100%" class="rf-dt" id="report" >
			<?php 
			$i = 0;
			while ($row=mysql_fetch_array($queryListErrorByIDPr)){
				$i++;
				$idtestproject = $row[IDTest];
				$idemplTestpro = $row[IDEmployee];
				$prdelete = $row[Delete];
				$titletestpro = $row[Title];
				$contenttestpro = $row[TextTest];
				$fullnames = $row[FullName];
				$time = $row[Time];
				$indexcomment = (($page-1)*5)+$i;
				$stringcolortest = substr($row[Title],0,-14);
				$color = substr($row[Title],-6);
				
				
				$stringcolor = substr($row[Comment_C],0,-14);
				$colorcomment = substr($row[Comment_C],-6);
				
				//tag html tranh be giao dien
				$stringcolor = strip_tags($stringcolor);
				?>
				
				<tr style="background: #f2f9ff" >
					<td class="rf-dt-c"
						style="width: 25px; vertical-align: middle; text-align: center;min-width: 25px"><?php echo $indexcomment;?>
					</td>
					
					<td class="rf-dt-c" 
						style="padding: 7px; vertical-align: middle; width: 50%;">
						<div class="rowMinHeight" align="left" style="width: 97%;">
							<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="showcommanderrorRecyclebin(<?=$indexcomment?>,'<?=$idtestproject?>','<?=$id_employee?>','<?=$id?>',1, this,'<?=$page?>');" class="titleError"> 
							<a class="bclick" style="color: #424242;cursor:pointer;padding:2px;">
							<?php 
							if(strlen($stringcolortest)==0){?>
								<font style="color:#6290ff "><?php echo  $titletestpro ?> </font>
							<?php 
							}
							switch ($color){
								case 'B023AB':
									?> <font style="color: #B023AB"><?php echo  $stringcolortest ?> </font> <?php	break;
								case '424242':
									?> <font style="color: #424242"><?php echo  $stringcolortest ?> </font> <?php	break;
								case '3DA850':
									?><font style="color: #3da850"><?php echo  $stringcolortest ?> </font> <?php	break;
								case 'B02323':
									?><font style="color: #B02323"><?php echo  $stringcolortest ?> </font> <?php	break;
								default:
									?> <font style="color:#424242"><?php echo  $stringcolortest ?> </font> <?php	break;
															}?> </a> </span>
							<div class="writeBy">
							
								<div align="right" style="width: 99%; float: left;">
								<span><?php 
									switch ($colorcomment){
										case 'B023AB':
											?> <font style="color: #B023AB"><?php 
											substringProvider::catchuoi($stringcolor,27);
											 ?></font>
											<?php	break;
										case '424242':
											?> <font style="color:#424242"><?php 
											substringProvider::catchuoi($stringcolor,27);
											 ?></font> <?php	break;
										case '3DA850':
											?><font style="color:#3da850"><?php 
											substringProvider::catchuoi($stringcolor,27);
											 ?></font> <?php	break;
										case 'B02323':
											?><font style="color:#B02323"><?php 
											substringProvider::catchuoi($stringcolor,27);
											 ?></font> <?php	break;
										default:
											?> <font style="color:#424242"><?php 
											substringProvider::catchuoi($stringcolor,27);
											 ?></font> <?php	break;
									}?> </span> <span style="font-weight: bold;"><?php  if ($row[FullName_C]!="") {
echo '('.$row[FullName_C].')';
}?></span>	
								</div>
							</div>
						</div>
					</td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 150px;">
						<?php echo $fullnames?></td>
					<td class="rf-dt-c"
						style="vertical-align: middle; text-align: center; width: 130px;"><?php echo $time?>
					</td>
					<td class="rf-dt-c" style="vertical-align: middle; width: 140px;"><div
							class="divInButton" style="text-align: center;">
							<?php 
							if($row[IDManager]==$id_employee){?>
								
								<span title="<?=$l_active?>" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" style="width:60px; cursor:pointer" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ active_test_project('<?=$idtestproject?>','<?=$id?>','<?=$id_employee?>','<?=$page?>',this); return true;}else{return false;}">
									<img src="images/p-active.png"  style="width: 20px;cursor: pointer;"/>
								</span>

								<span title="<?=$l_delete?>" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" style="width: 60px" 
								onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ delete_test_project_recyclebin('<?=$prdelete?>','<?=$idtestproject?>','<?=$id?>','<?=$id_employee?>','<?=$page?>',this); return true;}else{return false;}" >
									<img src="images/p-delete.png"  style="width: 20px;cursor: pointer;"/>

								</span>
							<?php }else if(($idemplTestpro==$id_employee) || ($_SESSION['posmanager']==1)){?>
								<span title="<?=$l_active?>" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" style="width:60px; cursor:pointer" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ active_test_project('<?=$idtestproject?>','<?=$id?>','<?=$id_employee?>','<?=$page?>',this); return true;}else{return false;}">
									<img src="images/p-active.png"  style="width: 20px;cursor: pointer;"/>
								</span>
								<span title="<?=$l_delete?>" onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" style="width: 60px" 
								onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){ delete_test_project_recyclebin('<?=$prdelete?>','<?=$idtestproject?>','<?=$id?>','<?=$id_employee?>','<?=$page?>',this); return true;}else{return false;}" >
									<img src="images/p-delete.png"  style="width: 20px;cursor: pointer;"/>
								</span>
							<?php } 
							else{?>
								<a href="#" style="width: 60px" class="odd1" ></a>
								<?php }?>	
						</div></td>
				</tr>
				
				
				
				<tr style="background: #f2f9ff; display:none" id="commentprojecthide" >
				</tr>
				
				<?php }?>
				
				<tr class="trfoot">
                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="5">
                        	<div style="text-align: center; width: 100%">
				<?php 
				
				 $re = mysql_query("SELECT tp.IDTest
			   		FROM pr_testproject tp, employee e WHERE tp.IDProject = '$id' AND e.IDEmployee = tp.IDEmployee 
			  		 AND tp.`Delete` = 1 ORDER BY IDTest DESC");
				 $number_of_page = ceil ( mysql_num_rows( $re ) / $rows_per_page ); 
				 $max_page = 2;
				 if ( $number_of_page > 1 ) { 
					 
				 	if($page!=1){?>
						<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=2&page=<?=1?>">
					 		<span class="button_next" style="border:none"><?php echo "<<"?></span></a> 
					 	<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=2&page=<?=($page-1)?>">
					 		<span onmouseover="" class="button_next" style="border:none"><?php echo "<"?></span></a> 
					<?php  }
					else{
						echo "<span class='button_next' style='cursor:default'><<</span>"; 
						echo "<span class='button_next' style='cursor:default'><</span>";
					} 
					if (!isset($_SESSION['prevstart'])) {
						$_SESSION['prevstart'] = 1;
					}
					
					if ($max_page < $number_of_page){
						if ($page<=1) {
							$_SESSION['prevstart'] = 1;
						}		
						elseif ($page>=$number_of_page) {
							$_SESSION['prevstart'] = $number_of_page-$max_page+1;
						}	
						elseif ($page<=$_SESSION['prevstart']) {
							$_SESSION['prevstart'] = $page - 1;
						}elseif ($page>=$_SESSION['prevstart']+$max_page-1) {
							$_SESSION['prevstart'] = $page - $max_page + 2;
							
						}		
					 	
					}
					$startpage = $_SESSION['prevstart'];
					$endpage = $max_page + $startpage;
					for ($i=$startpage ;$i<$endpage && $i<=$number_of_page; $i++) {
					 	if ($i == $page) {
				     	 	?><span class="button_next" style="border:none; cursor:default;"><b style="color: blue;"><?php echo $i;?></b></span><?php 
						}else {
				     		?><a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=2&page=<?=$i?>">
				     	 		<span class="button_next" style="border:none;color: #508e21;" ><b ><?php echo $i;?></b></span></a> <?php 
				   		}
					}
				
					 if($page!=$number_of_page){ ?>
						<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=2&page=<?=($page+1)?>">
					 		<span class="button_next" style="border:none"><?php echo ">"?> </span></a>
					 	<a href="project.php?projectDetail=project-detail&id=<?=$id?>&tab=2&page=<?=$number_of_page?>">
					 		<span class="button_next" style="border:none"><?php echo ">>"?> </span></a><?php ;}
					else{
						echo "<span class='button_next' style='cursor:default'>></span> ";
						echo "<span class='button_next' style='cursor:default'>>></span> ";
					}
				}
				?>
				</div>
				</td>
				</tr>
			</table>
			</div>
			</div>
<?mysql_close($connection);?>